#!/bin/sh
# --------------------------------------------
# Linuxrules + dzen2 vertical bars example.
# --------------------------------------------
# Last Revision:	Fri Oct 22 2010, 01:10:51
#
#  Copyright (C) 2010 Mario García H.

#  "THE BEER-WARE LICENSE" (Revision 42):
#  <code933k (AT) gmail> wrote this file. As long as you retain
#  this notice you can do whatever you want with this stuff.

#  If we meet some day, and you think this stuff is worth it,
#  you can buy me a BEER in return, Mario García H.

#  THIS IS FREE SOFTWARE PROVIDED AS-IS
#  THERE IS NO WARRANTY, TO THE EXTENT PERMITTED BY LAW.

# Cycle 20 times.
CYCLE=20

while test $CYCLE -gt 0
do
    # Read data
    eval $(linuxrules)

    # Our bar range conversion dzen2
    RANGE=$(expr $CPULOAD0 \* 11 / 100 )

    # Correct the output of CPULOAD so that low values don't
    # move the bar anoyingly. If it jumps, for example, from
    # 9 to 100 as it moves 2 characters away even with a
    # monotype (all characters are the same wide) font.

    # Thus, we add a 0 and obscure it. But there are more
    # methods to acomplish this.
    case ${#CPULOAD0} in
        2 ) CPULOAD0="^fg(black)0^fg()$CPULOAD0"
        ;;
        1 ) CPULOAD0="^fg(black)00^fg()$CPULOAD0"
        ;;
    esac

    # Output to dzen2 
    echo "cpu: $CPULOAD0 ^p(;+$(expr 12 - $RANGE))^r(7x$RANGE)"

    # Now, we can lesser the times output was shown
    CYCLE=$(expr $CYCLE - 1)

    # Sleep one second.
    sleep 1
done | dzen2 -fg gray -bg black

# Finally, if your bar is way over the text or just missplaced,
# play with values 11 and 12 above. Bars tend to vary depending
# on your default fonts.

# Enjoy linuxrules + dzen2 bars!

